<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Worker-helper</title>
</head>
<body>
<script>
  const response = "onmessage=function(e){postMessage('Worker: '+e.data);}";
  const response2 = "onmessage=function(e){postMessage('response: '+e.data);}";

  const worker = new Worker('worker-03-helper.js');

  /**
   * 第一个，将 worker 中的原始方法给替换掉了。
   */
  worker.postMessage(response);

  /**
   * 此处触发的是，response 中的 postMessage
   */
  worker.postMessage('xxxxx');

  /**
   * 替换后的函数中没有 eval(e.data)
   * 所以替换不成功
   */
  worker.postMessage(response2);

  worker.postMessage('vvvvvvv');

  worker.onmessage = function (e) {
    console.log(e.data);

    // 终止
    // worker.terminate();
  };

</script>
</body>
</html>
